#include "ButtonListArrow.h"

ButtonListArrow::ButtonListArrow(std::string path, int posX, int posY,
		Widget *parent, Listener* listener) :
		WidgetClickeable(path,posX, posY, parent) {

	this->listener = listener;
}
ButtonListArrow::ButtonListArrow(Color color, int w, int h,int posX, int posY,
		Widget *parent, Listener* listener) :
		WidgetClickeable(color,w,h,posX, posY, parent) {

	this->listener = listener;
}


void ButtonListArrow::handleEvent(Event event, Parcel* parentParcel) {
	if (!isMouseOver(event, parentParcel))
		return;

	if ((event.getType()) == MouseButtonPressed) {
		this->pressed = true;
		Logger::trace("ButtonListArrow", "handleEvent", "MOUSEBUTTONDOWN");
	} else if ((event.getType()) == MouseButtonReleased) {
		Logger::trace("ButtonListArrow", "handleEvent", "SDL_MOUSEBUTTONUP");
	}

	WidgetClickeable::handleEvent(event);
}

void ButtonListArrow::resolve() {
	if (this->pressed) {
		this->listener->execute();
	}

	WidgetClickeable::resolve();
	this->pressed = false;
}

bool ButtonListArrow::isMouseOver(Event event, Parcel* parentParcel) const {
	return ((event.getXCoordinate() > this->parcel->posX + parentParcel->posX)
			&& (event.getXCoordinate() < this->parcel->posX + this->parcel->width + parentParcel->posX)
			&& (event.getYCoordinate() > this->parcel->posY + parentParcel->posY)
			&& (event.getYCoordinate() < this->parcel->posY
					+ this->parcel->height + parentParcel->posY));
}
